package com.github.pojo;

import lombok.Data;

@Data
public class WsResult<T> extends WsBaseResult {
    private int device_type;
    private T data;
    private Role node_status;


    public WsResult() {}

    public WsResult(long request_id, int msg_type, T data) {
        super(request_id, msg_type);
        this.data = data;
    }

    public static WsResult<?> success(int msg_type) {
        return new WsResult<>(System.currentTimeMillis(), msg_type, Status.success());
    }

    public static WsResult<?> success(int msg_type, Object data) {
        return new WsResult<>(System.currentTimeMillis(), msg_type, data);
    }

    public static WsResult<?> error(int msg_type, String msg) {
        return new WsResult<>(System.currentTimeMillis(), msg_type, Status.error(msg));
    }

    public static WsResult<?> deviceOnline(int device_type) {
        WsResult<?> success = success( 4);
        success.setNode_status(new Role(device_type, 1));
        return success;
    }

    public static WsResult<?> deviceOffline(int device_type) {
        WsResult<?> success = success(4);
        success.setNode_status(new Role(device_type, 2));
        return success;
    }

    @Data
    private static class Status {
        private int status;
        private String msg;

        public Status() {}

        public Status(int status, String msg) {
            this.status = status;
            this.msg = msg;
        }

        public static Status success() {
            return new Status(com.github.util.Status.SUCCESS.getStatus(), "成功");
        }

        public static Status error(String msg) {
            return new Status(com.github.util.Status.FAILED.getStatus(), msg);
        }
    }

    @Data
    public static class Role {
        private String account;
        private int role;
        private int status;

        public Role() {}

        public Role(int role, int status) {
            this.role = role;
            this.status = status;
        }
    }
}
